﻿<!DOCTYPE html>
<html>
    <head>
        <title>在线部署平台</title>
        <script type="text/javascript">
        <!--

            var id, content, l, p, m, request;

            function Upload()
            {
                if (l > 0)
                {
                    m = l;
                    if (m > 1000000)
                        m = 1000000;
                    request = new XMLHttpRequest();
                    request.open("POST", "Write.aspx?id=" + id, true);
                    request.send(content.substr(p, m));
                    request.onreadystatechange = function()
                    {
                        if (request.readyState == 4)
                        {
                            p += m;
                            l -= m;
                            SubmitButton.value = parseInt(99 * p / (p + l)) + "%";
                            if (request.status < 300)
                                Upload();
                            else
                            {
                                window.alert("部署失败:\n\n" + request.responseText);
                                SubmitButton.value = "部署";
                                SubmitButton.disabled = false;
                            }
                        }
                    };
                }
                else
                {
                    request = new XMLHttpRequest();
                    request.open("GET", "End.aspx?id=" + id + "&path=" + encodeURIComponent(site.value), true);
                    request.send();
                    request.onreadystatechange = function()
                    {
                        if (request.readyState == 4)
                        {
                            SubmitButton.value = "100%";
                            if (request.status < 300)
                                window.alert("部署成功");
                            else
                                window.alert("部署失败:\n\n" + request.responseText);
                            SubmitButton.value = "部署";
                            SubmitButton.disabled = false;
                        }
                    };
                }
            }

            function OnSubmit()
            {
                SubmitButton.disabled = true;
                SubmitButton.value = "0%";
                if (filesUploaded.files.length >= 1)
                {
                    var reader = new FileReader();
                    reader.readAsBinaryString(filesUploaded.files[0]);
                    reader.onload = function(e)
                    {
                        content = window.btoa(this.result);
                        l = content.length;
                        p = 0;
                        request = new XMLHttpRequest();
                        request.open("GET", "Begin.aspx", true);
                        request.send();
                        request.onreadystatechange = function()
                        {
                            if (request.readyState == 4)
                            {
                                id = request.responseText;
                                if (request.status < 300)
                                    Upload();
                                else
                                {
                                    window.alert("部署失败:\n\n" + request.responseText);
                                    SubmitButton.value = "部署";
                                    SubmitButton.disabled = false;
                                }
                            }
                        };
                    }
                }
            }

        //-->
        </script>
    </head>
    <body>
        站点:<select id="site">
            <option value="D:\WebServer\BJGHTV\DEV">开发1</option>
            <option value="D:\WebServer\BJGHTV\DEV2">开发2</option>
            <option value="D:\WebServer\BJGHTV\DEV3">开发3</option>
            <option value="D:\WebServer\BJGHTV\DEV4">开发4</option>
            <option value="D:\WebServer\BJGHTV\TEST">测试</option>
            <option value="D:\WebServer\BJGHTV\Deploy1">部署1</option>
            <option value="D:\WebServer\BJGHTV\Deploy2">部署2</option>
        </select><br />
        Zip文件:<input id="filesUploaded" type="file" /><br />
        <input id="SubmitButton" type="button" value="部署" onclick="javascript:OnSubmit()" />
    </body>
</html>
